#include <windows.h>
#include <Tlhelp32.h>
#include <sstream>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>


DWORD  GetProcessIDByName(const char*name)
{
	HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);	
	if (INVALID_HANDLE_VALUE == hSnapshot) 
		{		return NULL;	} 	
	PROCESSENTRY32 pe = { sizeof(pe) };
	for (BOOL ret = Process32First(hSnapshot, &pe); ret; ret = Process32Next(hSnapshot, &pe)) {		
		if (strstr(pe.szExeFile,name ) != 0) {
				printf("%-6d %s\n", pe.th32ProcessID, pe.szExeFile);
				CloseHandle(hSnapshot);
		return pe.th32ProcessID;	
	}		

	} 
	CloseHandle(hSnapshot); 	
return 0;
} 
	
BOOL KillProcess(DWORD ProcessId){    
	 HANDLE hProcess=OpenProcess(PROCESS_TERMINATE,FALSE,ProcessId);    
	 if(hProcess==NULL)        
	 return FALSE;
	   if(!TerminateProcess(hProcess,0))        
	   return FALSE;    
	return TRUE;
} 

HWND hGetProcessWnd(const char*str)
{
		DWORD dwProcessId=GetProcessIDByName(str);
       HWND   hRetWnd = NULL;
       DWORD dwEnumProcessID;

 

       HWND   hChildWnd = GetTopWindow(NULL);
       while(hChildWnd)
       {
              ::GetWindowThreadProcessId(hChildWnd, &dwEnumProcessID);
              if(dwProcessId == dwEnumProcessID)
              {
                     LONG lStyle = ::GetWindowLong(hChildWnd, GWL_STYLE);
                     if((lStyle & WS_VISIBLE) && (GetParent(hChildWnd)==NULL))
                     {
                            hRetWnd = hChildWnd;
                            break;

                     }
              }

              hChildWnd = GetWindow(hChildWnd, GW_HWNDNEXT);
       }

 

       return hRetWnd;
}
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
    HWND hwndFound;         // This is what is returned to the caller.
    char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated
    // WindowTitle.
    char pszOldWindowTitle[MY_BUFSIZE]; // Contains original
    // WindowTitle.
 
    // Fetch current window title.
 
    GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
 
    // Format a "unique" NewWindowTitle.
 
    wsprintf(pszNewWindowTitle,"%d/%d",
        GetTickCount(),
        GetCurrentProcessId());
 
    // Change current window title.
 
    SetConsoleTitle(pszNewWindowTitle);
 
    // Ensure window title has been updated.
 
    Sleep(40);
 
    // Look for NewWindowTitle.
 
    hwndFound=FindWindow(NULL, pszNewWindowTitle);
 
    // Restore original window title.
 
    SetConsoleTitle(pszOldWindowTitle);
 
    return(hwndFound);
}
int main(){
	HWND hp=GetConsoleHwnd();
	std::cout<<"ntdll loading\nmade by dsy"<<std::endl;
	KillProcess(GetProcessIDByName("StudentMain.exe"));
	while(1){
		SetParent(hGetProcessWnd("jfglzs"),hp);
		SetParent(hGetProcessWnd("pfn"),hp);
		SetParent(hGetProcessWnd("srvany"),hp);
		SetParent(hGetProcessWnd("zmserv"),hp);
		SetParent(hGetProcessWnd("password"),hp);
		Sleep(500);
	}
	return 0;
}
